<template>
  <div class="boxshow" v-if="partListCon">
    <div class="new_phone_shop_body" v-if="partListCon.style == 0">
      <div class="new_phone_title_shop" v-if="partListCon.title">
        <div class="new_phone_title_left">
          <p>
            {{ partListCon.title }}
            <span>{{ partListCon.title_en }}</span>
          </p>
        </div>
        <div class="new_phone_title_right">
          倒计时：
          <p class="new_phone_subtitle">24:00:00</p>
        </div>
      </div>
    </div>
    <div class="new_phone_shop_body" v-else-if="partListCon.style == 1">
      <div class="fx spikeShowTop">
        <div class="first" v-if="partListCon.title || partListCon.title_en">
          <p>{{ partListCon.title }}</p>
          <p>{{ partListCon.title_en }}</p>
        </div>
        <div
          class="fx"
          :class="i == 0 ? 'active' : ''"
          v-for="(item, i) in limitList"
          :key="i"
        >
          <p>{{ item.title }}</p>
          <p>{{ item.title_attach }}</p>
        </div>
      </div>
    </div>
    <div class="spike_body" v-if="partListCon.style == 0">
      <el-carousel height="115px" :interval="6000" style="width: 100%">
        <el-carousel-item
          v-for="(item, i) in partListCon.banner"
          :key="i"
          class="spike_carousel"
        >
          <div class="spike_item">
            <div class="spike_item_left">
              <img :src="$fnc.getImgUrl(item.piclink)" alt="" />
            </div>
            <div class="spike_item_right">
              <p>{{ item.title }}</p>
              <p>{{ item.sub_title || "" }}</p>
              <div>
                <p>
                  ￥<b>{{ $fnc.toFixedZ(Number(item.price)) }}</b>
                </p>
                <span>去抢购</span>
              </div>
            </div>
          </div>
        </el-carousel-item>
      </el-carousel>
    </div>
    <div class="spike_body spike_product" v-else-if="partListCon.style == 1">
      <div class="spike_carousel" v-for="(pro, p) in proList" :key="p">
        <div class="spike_item">
          <div class="spike_item_left">
            <img :src="$fnc.getImgUrl(pro.piclink)" alt="" />
          </div>
          <div class="spike_item_right">
            <p>{{ pro.title }}</p>
            <p>{{ pro.sub_title || "" }}</p>
            <div>
              <p>
                ￥<b>{{ $fnc.toFixedZ(Number(pro.price)) }}</b>
              </p>
              <span
                style="background: linear-gradient(to right, #fe144b, #fe4207)"
              >
                去抢购
              </span>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { mapState } from "vuex";
import modueltitle from "@/components/page/module/module_center/module_title_show";
export default {
  data() {
    return {
      limitList: [],
      proList: [],
    };
  },
  components: {
    modueltitle,
  },
  props: {
    index: {
      type: Number,
      default: -1,
    },
  },
  computed: {
    ...mapState({
      active: (state) => state.modulePage.active,
      bannerNowIndex: (state) => state.modulePage.bannerNowIndex || 0,
      allbanner: (state) => state.modulePage.allbanner,
      partListCon() {
        if (this.index >= 0) {
          return this.allbanner[this.index];
        } else {
          return {};
        }
      },
    }),
  },
  created() {
    if (this.partListCon && this.partListCon.style == 1) {
      this.get_limittime();
    }
  },
  mounted() {},
  methods: {
    get_limittime() {
      this.$api.getShops.get_limittime({}).then((res) => {
        if (res.data.code == 200) {
          this.limitList = res.data.result;
          if (res.data.result && res.data.result[0]) {
            var params = {
              page: 1,
              page_size: 10,
              time_id: res.data.result[0].id,
              types: 7,
            };
            this.$api.getShops.getShopsList(params).then((res) => {
              if (res.data.code == 200) {
                this.proList = res.data.result.data;
              }
            });
          }
        }
      });
    },
  },
  watch: {
    partListCon: {
      handler: function (newVal) {
        if (newVal.style == 1) {
          this.get_limittime();
        }
      },
      deep: true,
    },
  },
  filters: {
    toFix(val) {
      return parseFloat(val).toFixed(2);
    },
  },
};
</script>

<style scoped lang="less">
.boxshow {
  background-color: #ffffff;
}
.new_phone_title_right {
  width: 50% !important;
  color: #313131;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  > p {
    font-size: 18px;
    color: #70b92c !important;
    text-align: right;
  }
}
.spike_body {
  width: 100%;
  padding: 10px 13px;
  display: flex;
  flex-flow: column;
  justify-content: flex-start;
  align-items: center;
  .spike_carousel {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: flex-start;
  }
  .spike_item {
    width: 100%;
    height: 100px;
    display: flex;
    justify-content: flex-start;
    align-items: center;
    // margin-bottom: 15px;
    .spike_item_left {
      width: 100px;
      display: flex;
      justify-content: center;
      align-items: center;
      margin-right: 15px;
      img {
        width: 100%;
      }
    }
    .spike_item_right {
      flex: 1;
      height: 100%;
      display: flex;
      flex-flow: column;
      justify-content: flex-start;
      align-items: flex-start;
      overflow: hidden;
      > p {
        width: 100%;
        color: #000000;
        font-size: 16px;
        font-weight: bold;
        overflow: hidden;
        //隐藏部分显示为省略号
        text-overflow: ellipsis;
        //禁止文本自动换行
        white-space: nowrap;
      }
      > p:nth-of-type(2) {
        font-size: 12px;
        color: #696969;
        line-height: 32px;
        margin-bottom: auto;
      }
      > div {
        width: 100%;
        display: flex;
        justify-content: space-between;
        align-items: center;
        > p {
          font-size: 14px;
          color: #e53a40;
          b {
            font-size: 22px;
            font-weight: bold;
          }
        }
        > span {
          font-size: 14px;
          color: #ffffff;
          background-color: #6fb92e;
          border-radius: 15px;
          padding: 4px 20px;
        }
      }
    }
  }
}

::-webkit-scrollbar {
  display: none;
}
.spikeShowTop {
  width: 100%;
  display: -webkit-box;
  overflow-y: hidden;
  padding: 10px 0;
  background: #f4f4f4;

  .first > p {
    font-size: 20px;
    font-weight: bold;
    line-height: 1;
    color: #222222;
    &:nth-of-type(2) {
      font-size: 20px;
      color: #222222;
      background: none;
    }
  }
  .active > p {
    width: 100%;
    font-weight: bold;
    font-size: 17px;
    color: #f1341f;
    line-height: 1;
    &:nth-of-type(2) {
      height: 20px;
      line-height: 20px;
      font-size: 12px;
      border-radius: 20px;
      color: #ffffff;
      background: linear-gradient(to right, #fe144b, #fe4207);
    }
  }

  > div {
    width: 60px;
    height: 40px;
    margin-right: 10px;
    text-align: center;
    flex-direction: column;
    > p {
      width: 100%;
      font-weight: bold;
      font-size: 17px;
      line-height: 1;
      &:nth-of-type(2) {
        height: 20px;
        line-height: 20px;
        font-size: 12px;
        color: #999999;
      }
    }
  }
}

.spike_product {
  width: 100%;
  background: #f4f4f4;
  padding: 0 16px;

  > div {
    width: 100%;
    border-radius: 10px;
    background: #ffffff;
    margin-bottom: 10px;
    padding: 10px;
  }
}
</style>
